{include file="publics/head"/}

<body class="no-skin">
{include file="publics/header"/}
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    {include file="publics/sidebar"/}
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            {include file="publics/breadcrumbs"/}
            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                {include file="publics/set"/}

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="cf">
                            <form class="form-inline" action="{:url('index')}" method="get">
                                <a class="btn btn-info" href="{:url('add')}" value="">新增</a>

                            </form>
                        </div>
                        <div class="space-4"></div>
                        <form id="form" method="post" action="{:url('del')}">
                            <table class="table table-striped table-bordered">
                                <thead>
                                <tr>
                                    <th class="center"><input class="check-all" type="checkbox" value=""></th>
                                    <th class="col-xs-4">Banner名称</th>
                                    <th class="col-xs-4">Banner链接地址</th>
                                    <th>发布时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {volist name="list" id="val"}
                                    <tr>
                                        <td class="center"><input class="banner_id" type="checkbox" name="banner_ids[]"
                                                                  value="{$val['banner_id']}"></td>

                                        <td>{$val['banner_title']}</td>
                                        <td>{$val['banner_url']}</td>
                                        <td>{$val['t']|date="Y-m-d H:i:s"}</td>
                                        <td><a href="{:url('edit',array('banner_id'=>$val['banner_id']))}"><i
                                                class="ace-icon fa fa-pencil bigger-100"></i>修改</a>&nbsp&nbsp;<a
                                                href="javascript:;" val="{:url('del',array('banner_id'=>$val['banner_id']))}" class="del"><i
                                                class="ace-icon fa fa-trash-o bigger-100 red"></i>删除</a></td>
                                    </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </form>
                        <div class="msdn">{$list|raw}</div>
                        <div class="cf">
                            <input id="submit" class="btn btn-info" type="button" value="删除">
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    {include file="publics/footer"/}

</div><!-- /.main-container -->

{include file="publics/footerjs"/}
<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(function () {
        $(".check-all").click(function () {
            $(".banner_id").prop("checked", this.checked);
        });
        $(".banner_id").click(function () {
            var option = $(".banner_id");
            option.each(function (i) {
                if (!this.checked) {
                    $(".check-all").prop("checked", false);
                    return false;
                } else {
                    $(".check-all").prop("checked", true);
                }
            });
        });
        $("#submit").click(function () {
        	var banner_id = new Array();
			$("input[name='banner_ids[]']:checked").each(function(i, o) {
                banner_id.push($(this).val());
			});
            bootbox.confirm({
                title: "系统提示",
                message: "是否要删除所选友链？",
                callback: function (result) {
                    if (result) {
                    	$.ajax({
                        	type:"post",
                        	url:"{:url('del')}",
                        	data:'banner_id='+banner_id,
                        	//dataType:"",
                        	error:function(){
                        		return false;
                        	},
                        	success:function(data){
                        		console.log(data);
                        		bootbox.alert({  
                                    buttons: {  
                                       ok: {label: '确定',className: 'btn-danger'}  
                                    },  
                                    message: data.message,  
                                    callback: function() {  
                                        if(data.flag == 0){
           	                       			location.reload(); 
           	                       		}
                                    },  
                                    title: "系统提示",  
                                });
                        	}
                        });
                    }
                },
                buttons: {
                    "cancel": {"label": "取消"},
                    "confirm": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
        });
        $(".del").click(function () {
            var url = $(this).attr('val');
            bootbox.confirm({
                title: "系统提示",
                message: "是否要该友链？",
                callback: function (result) {
                    if (result) {
                        $.ajax({
                        	type:"post",
                        	url:url,
                        	error:function(){
                        		return false;
                        	},
                        	success:function(data){
                        		//alert(data.message);
                        		bootbox.alert({
                                    buttons: { ok: {label: '确定',className: 'btn-danger'} },  
                                    message: data.message,  
                                    callback: function() { if(data.flag == 0){ location.reload(); } },  
                                    title: "系统提示",  
                                });//
                        	}
                        });
                    }
                },
                buttons: {
                    "cancel": {"label": "取消"},
                    "confirm": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
        });
    })
</script>
</body>
</html>
